package com.lollipop.programming.designpattern.strategy;

import java.math.BigDecimal;

/**
 * @Author Lollipop
 * @Version 1.0
 * @Date 2025/4/10 13:50
 * @Description 支付策略上下文
 */
public class PaymentContext {
    private PaymentStrategy paymentStrategy;

    /**
     * 获取支付策略 - 构造函数方式
     *
     * @param paymentStrategy
     */
    public PaymentContext(PaymentStrategy paymentStrategy) {
        this.paymentStrategy = paymentStrategy;
    }

    /**
     * 执行支付
     *
     * @param amount
     * @return
     */
    public boolean executePayment(BigDecimal amount) {
        return paymentStrategy.pay(amount);
    }

    /**
     * 设置支付策略 - setter方式
     *
     * @param paymentStrategy
     */
    public void setPaymentStrategy(PaymentStrategy paymentStrategy) {
        this.paymentStrategy = paymentStrategy;
    }
}
